package main

import (
	"fmt"
	"io"
	"os"
)

/**
文件操作
*/

func main() {

	file, e := os.Open("/Users/mocaris/DevWork/GoProject/GoDemo/com.mocaris.demo/learn/iodemo/main.txt")
	if nil != e {
		fmt.Println(e.Error())
	}

	bytes, _ := ReadFromReade(file, 1024)

	fmt.Println(string(bytes))
}

/**
io读取
*/
func ReadFromReade(reader io.Reader, num int) ([]byte, error) {

	bytes := make([]byte, num)
	length, err := reader.Read(bytes)

	if length > 0 {
		return bytes[:length], nil
	}
	return nil, err
}
